package cn.seocoo.platform.web.controller.top;

import cn.seocoo.platform.common.annotation.Log;
import cn.seocoo.platform.common.core.controller.BaseController;
import cn.seocoo.platform.common.core.domain.AjaxResult;
import cn.seocoo.platform.common.core.page.TableDataInfo;
import cn.seocoo.platform.common.enums.BusinessType;
import cn.seocoo.platform.common.utils.poi.ExcelUtil;
import cn.seocoo.platform.top.domain.TopType;
import cn.seocoo.platform.top.service.ITopTypeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 置顶类型 信息操作处理
 * 
 * @author wujian
 * @date 2019-12-26
 */
@Controller
@RequestMapping("/top/topType")
public class TopTypeController extends BaseController
{
    private String prefix = "top/topType";
	
	@Autowired
	private ITopTypeService topTypeService;
	
	@RequiresPermissions("top:topType:view")
	@GetMapping()
	public String topType()
	{
	    return prefix + "/topType";
	}
	
	/**
	 * 查询置顶类型列表
	 */
	@RequiresPermissions("top:topType:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(TopType topType)
	{
		startPage();
        List<TopType> list = topTypeService.selectTopTypeList(topType);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出置顶类型列表
	 */
	@RequiresPermissions("top:topType:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TopType topType)
    {
    	List<TopType> list = topTypeService.selectTopTypeList(topType);
        ExcelUtil<TopType> util = new ExcelUtil<TopType>(TopType.class);
        return util.exportExcel(list, "topType");
    }
	
	/**
	 * 新增置顶类型
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存置顶类型
	 */
	@RequiresPermissions("top:topType:add")
	@Log(title = "置顶类型", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(TopType topType)
	{		
		return toAjax(topTypeService.insertTopType(topType));
	}

	/**
	 * 修改置顶类型
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		TopType topType = topTypeService.selectTopTypeById(id);
		mmap.put("topType", topType);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存置顶类型
	 */
	@RequiresPermissions("top:topType:edit")
	@Log(title = "置顶类型", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(TopType topType)
	{		
		return toAjax(topTypeService.updateTopType(topType));
	}
	
	/**
	 * 删除置顶类型
	 */
	@RequiresPermissions("top:topType:remove")
	@Log(title = "置顶类型", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(topTypeService.deleteTopTypeByIds(ids));
	}
	
}
